<?php

require_once 'classes/LightPressPlugin.php';

class PostExtra extends LightPressPlugin {
    
    var $constructor_args = array(
        'link'=>'link structure');
    var $default_context = 7; // LP_CONTEXT_INDEX | LP_CONTEXT_ARCHIVES | LP_CONTEXT_CATEGORY;
    var $description = 'Add \'continue reading\' and \'comments\' links to the post content';

    var $active = true;
    var $hooks = array('get_posts_loop');
    
    var $link = '<a class="structure" href="{option_url}/%s#%s">%s</a>';

    function PostExtra(&$frontend, $args, $dummy_run=false) {
        $this->LightPressPlugin($frontend, $args, $dummy_run);
        if (!$dummy_run && basename($_SERVER['PHP_SELF']) != 'index.php')
            $this->active = false;
    }

    function hide() {
        return;
    }
    
    function run($hook, &$post) {
        if (!isset($post['post_comments'])) // 'simple' mode, used mainly for feeds
            return;
        if (empty($post['post_more'])) {
            $text = sprintf('<span title="%s comments" style="font-style: italic;">comment</span>', $post['post_comments']);
            $anchor = "add_comment";
        } else {
            $text = sprintf('<span title="continue reading, %s comments" style="font-style: italic;">continue reading<!--&#9658; &#10238;--></span>', $post['post_comments']);
            $anchor = "more";
        }
        $link = sprintf($this->link, $post['post_permalink'], $anchor, $text);
        $content =& $post['post_content'];
        if (substr($content, -4) == '</p>') {
            $content = substr($content, 0, -4) . "&nbsp;$link</p>";
        } else {
            $content .= "$link";
        }
    }

}

?>